<?php
namespace Admin\Controller;
use Think\Controller;
class UsersController extends Controller {
    public function showlist()
    {
        $data =  D('Users')->search();
        $this->assign($data);
        $this->display();
    }
    public function member_edit()
    {
        if(IS_POST){
            $data = I('post.');
            //$newpassword = I('post.newpassword');
            $z = D('Users')->save($data);
        }else{
            $id = I('get.id');
            $this->assign('id',$id);
            $this->display();
        }
    }
    public function member_add()
    {   
        if(IS_POST){
            $data = I('post.');
            $data['id'] = D('Users')->max('id')+1;
            $z = D('Users')->add($data); 
        }else{
            $this->display();            
        }
    }
    public function change_password()
    {
        if(IS_POST){
            $id = I('post.id');
            $newpassword = I('post.newpassword');
            $z = D('Users')->where('id='.$id)->setField('password',$newpassword);
        }else{
            $id = I('get.id');
            $nickname = D('Users')->where('id='.$id)->getField('nickname');
            $this->assign('id',$id);
            $this->assign('nickname',$nickname);
            $this->display();
        }  
    }
    public function member_del()
    {
        $id = I('get.id');
        $z = D('Users')->where('id='.$id)->setField('is_delete','1');
        if($z){
            echo 'ok';
        }
    }
    public function member_stop()
    {
        $id = I('get.id');
        $z = D('Users')->where('id='.$id)->setField('is_close','1');
        if($z){
            echo 'ok';
        }
    }
    public function member_start()
    {
        $id = I('get.id');
        $z = D('Users')->where('id='.$id)->setField('is_close','0');
        if($z){
            echo 'ok';
        }
    }
    public function settings()
    {   
        if(IS_POST){
            $array['limit_money'] = I('post.limit_money');
            $url = APP_PATH.'Admin/Conf/user.txt'; 
            file_put_contents($url, json_encode($array));

            //echo $url;die;
            // $d = file_get_contents('../Conf/user.txt');
            // var_dump($d);die;


        }else{
            // $url = APP_PATH.'Admin/Conf/user.txt';
            // $array = file_get_contents($url);
            // var_dump($array);die;
            // print_r($array);die; 

            $this->display();            
        }
    }
    public function a(){
        $url = APP_PATH.'Admin/Conf/user.txt';
        $da= file_get_contents($url);
        print_r(json_decode($da,true));
    }
    public function turn_cash()
    {
        $cash = M('Turn_cash')->select();
        // print_r($data);die;
        $this->assign('cash',$cash);
        $this->display();
    }
    public function shenhe()
    {
        $id = I('get.id');
        $is_check = I('get.is_check');
        $z = M('Turn_cash')->where('id='.$id)->setField('is_check',$is_check);

    }



}